package com.orhon.smartcampus.modules.material.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import com.orhon.smartcampus.modules.base.entity.Schools;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_unit", schema = "smartcloud", catalog = "")
public class Unit {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "unit_code", nullable = true, length = 20)
    private String unitCode;
    @Column(name = "unit_tel", nullable = true, length = 11)
    private String unitTel;
    @Column(name = "floor_num", nullable = true)
    private Integer floorNum;
    @Column(name = "created_at", nullable = true)
    private Date createdAt;
    @Column(name = "created_by", nullable = true)
    private Integer createdBy;
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    @Column(name = "updated_by", nullable = true)
    private Integer updatedBy;
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;
    @Column(name = "unit_name", nullable = true)
    private String unitName;
    @Column(name = "unit_manager", nullable = true)
    private String unitManager;

    @ManyToOne
    @JoinColumn(name = "buildings_id", referencedColumnName = "id")
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action= NotFoundAction.IGNORE)
    private Buildings materialBuildingsByBuildingsId;

    @ManyToOne
    @JoinColumn(name = "school_id", referencedColumnName = "id")
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action=NotFoundAction.IGNORE)
    private Schools baseSchoolsBySchoolId;
}
